/*
 * ==================================================
 * 项目开发者：JerryStark
 * 开发者Email：4771007@qq.com
 * 开发者QQ:4771007
 * 开发范围：web，wap，android,ios,osx or win or linux 应用
 * ==================================================
 */
package RTGame.Server;

import RTGame.Configs.Load;
import RTGame.Main;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

/**
 * 所有行为类型的具体执行类
 *
 * @author jerry
 */
public class Action {

    /**
     * 关闭服务器端
     *
     * @param ClientMsg
     * @return
     */
    public static String StopServer(JsonObject ClientMsg) {
        //关闭监听服务器
        Main.ServerManage.Stop();
        return BackJsonMsg("ok", "服务器端2分钟内自动关闭", null);

    }

    /**
     * 获取服务器目前状态信息
     * <br>包含了具体所有的状态
     *
     * @return
     */
    public static String GetServerStatus(JsonObject ClientMsg) {

        //返回端口服务器状态和抓取状态
        JsonObject info = new JsonObject();
        info.addProperty("ServerStatus", Main.ServerManage.rtSocket.SerStatus);
        info.add("ServerInfo",Load.MainConfig);
       info.add("GetLotteryInfo",Load.LotteryConfig);
        return BackJsonMsg("ok", "", info);
    }

    /**
     * 统一返回方法,整理数据为统一json格式字符串
     *
     * @param status
     * @param msg
     * @param back_data
     * @return
     */
    public static String BackJsonMsg(String status, String msg, JsonObject back_data) {

        JsonObject back_jsonobject = new JsonObject();
        back_jsonobject.addProperty("status", status);
        back_jsonobject.addProperty("msg", msg);
        back_jsonobject.add("data", back_data);

        //转成json字符串
        Gson gson = new Gson();
        String back_string = gson.toJson(back_jsonobject);
//        System.err.println(back_string);
        String ReadMessage = "HTTP/1.1 200 \r\n" + "Content-Type: text/html\r\n"
                + "\r\n" + back_string;

        return ReadMessage;
    }
}
